package com.jiawa.wiki.Controller;

import com.jiawa.wiki.req.EbookQueryReq;
import com.jiawa.wiki.req.EbookSaveRep;
import com.jiawa.wiki.resp.CommonResp;
import com.jiawa.wiki.resp.EbookQueryResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/ebook")
public class EbookController {

    //依赖注入
    @Resource
    public EbookService ebookService;
    @GetMapping("/list")
    public CommonResp<PageResp<EbookQueryResp>> list(@Valid EbookQueryReq req){
        PageResp<EbookQueryResp> list = ebookService.getlist(req);
        CommonResp<PageResp<EbookQueryResp>> resp =new CommonResp<>();
        resp.setContent(list);
        return resp;

    }
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookSaveRep req){
        ebookService.save(req);

        CommonResp resp =new CommonResp<>();

        return resp;
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable long id){
        ebookService.delete(id);

        CommonResp resp =new CommonResp<>();

        return resp;

}}

